package work.comeback.omo.util.configuration.service;

import work.comeback.omo.util.configuration.interfaces.DatabaseConfigure;
import work.comeback.omo.util.configuration.model.ConfigOptions;
import work.comeback.omo.util.configuration.model.MySQLConfig;
import work.comeback.omo.util.configuration.model.SQLiteConfig;

public class DbConfigFactory {
    public static DatabaseConfigure create(ConfigOptions configOptions) {
        String dbType = configOptions.getDbType().toLowerCase();

        return switch (dbType) {
            case "mysql" -> mysqlConfigure(configOptions);
            case "sqlite" -> sqliteConfigure(configOptions);
            default -> throw new IllegalArgumentException("Unsupported database type: " + dbType);
        };
    }

    public static DatabaseConfigure mysqlConfigure(ConfigOptions configOptions) {
        return new MySQLConfig(configOptions.getDbType(), configOptions.getMysqlUrl(), configOptions.getMysqlUser(), configOptions.getAdminPassword());
    }

    public static DatabaseConfigure sqliteConfigure(ConfigOptions configOptions) {
        return new SQLiteConfig(configOptions.getDbType(), configOptions.getSqliteUrl());
    }
}
